package automaton;

import java.util.*;

import coins.Coin;

///////////////////////////////////////////////////////// File CoinStore.java /////////////////////////////////////////////////////////
public class CoinStore {
	private Queue<Coin> store = new LinkedList<Coin>();
	private Object key = new Object();

	public CoinStore() {
	}

	synchronized public  void throwInto(Coin c) {
		if( store.isEmpty() ) {
			notify();
		}
		store.add(c);
	}

	synchronized public  Coin getOut() {
		Coin c;

		try {
			if (store.isEmpty()) {
				wait();
			}
		} catch (InterruptedException e) {

		}

		c = store.remove();

		return c;
	}

	public void printStoreContent() {
		synchronized (key) {
			System.out.println("\nStore contains the following coins:");

			for (Coin c : store)
				System.out.println(c);
		}

	}
}